import Mock from 'mockjs';
import ApiPath from '../api/apiPath/login'

const SERVER_HOST = process.env.VUE_APP_BASE_API;
console.log('login被调用', SERVER_HOST + 'doLogin')
Mock.mock(ApiPath.user.getLoginPath, 'post', function(data) {
    console.log(data.body)
    const resJson = parse(data.body)
    console.log('data', resJson)

    if (resJson.userName === 'admin' && resJson.passWord === '123456') {
        return Mock.mock({
            code: 200,
            message: '登陆成功'
        })
    }
    return Mock.mock({
        code: 400,
        message: '重新登陆'
    })
})

function parse(params) {
    const res = params.split('&'); //将参数分割成数组
    const json = new Object();
    for (let i = 0; i < res.length; i++) {
        json[res[i].split('=')[0]] = res[i].split('=')[1];
    }
    return json;
}
